package com.jit.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.jit.app.model.Constants;

import java.util.List;

public class AdPromotionAdapter extends BaseAdapter {
    public AdPromotionAdapter(){}

    Context context;
    List<JSONObject> data;
    int itemLayoutId;

    public AdPromotionAdapter(Context context, List<JSONObject> data, int itemLayoutId){
        this.context =context;
        this.data = data;
        this.itemLayoutId = itemLayoutId;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return data.get(position).getLong("id");
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(itemLayoutId,null);
        }

        ImageView imageView = (ImageView) convertView;
        //更新子项数据
        JSONObject jsonObject = data.get(position);
        Glide.with(context).load(Constants.HOST.FILE_HOST+jsonObject.getString("picPath")).into(imageView);

        return convertView;
    }
}